//logs.js
const common = require('../../utils/common.js');
const app=getApp();
Page({
  data: {
    userId:'',       //用户ID
    userInfo:{},    //用户信息
    bgi:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1522247346208&di=d21045f66e8157e0fe2ff922aa721ff1&imgtype=0&src=http%3A%2F%2Fpic32.nipic.com%2F20130819%2F5252423_143927588000_2.png',

  },
  //更新用户信息
  loadInfo:function(){
      var bgi = wx.getStorageSync('me_bgi');
      if(bgi){
          this.setData({
              bgi: bgi,
          });
      }
      
      var is_login = common.checkLogin(false);
      if (!is_login) return;
      var that = this;
      var token = common.getToken();
      var userId = common.getUserId();
      var data = { token: token, userId: userId };
      var url = `${app.apiHost}centers/index`;     //发而评论接口
      var msg = '';
      var func = function (content) {
          that.setData({
              userInfo: content,
              userId:userId,
          });

      };
      var res = common.request(url, data, msg, func, that);   
  },
  onLoad: function () {
      
  },
  onShow:function(){
      this.loadInfo();
  },
  //签到
  sign: function () {
      var is_login = common.checkLogin();
      if (!is_login) return;      
  },
  //编辑资料入口
  edit:function(){
      var is_login = common.checkLogin();
      if (!is_login) return;  
      var userId=this.data.userId;
      
      wx.navigateTo({         
          url: `userinfo/index`,
      })
  },
  //注销
  logout:function(){
      common.logout();
  },
  //跳转至我的文章页面
  to_article_me:function(){
      var is_login = common.checkLogin();
      if (!is_login) return;
      wx.navigateTo({
          url: 'article/index',
      })
  },
  //跳转至我的收藏页面
  to_collect_me: function () {
      var is_login = common.checkLogin();
      if (!is_login) return;
      wx.navigateTo({
          url: 'collect/index',
      })
  },
  //跳转至我的收藏页面
  to_balance_me: function () {
      var is_login = common.checkLogin();
      if (!is_login) return;
      wx.navigateTo({
          url: 'balance/index',
      })
  },
  //跳转至消息页面
  to_msg_me:function(){
      var is_login = common.checkLogin();
      if (!is_login) return;
      wx.navigateTo({
          url: 'msg/index',
      })
  },
  //点击积分提现处理程序
  tixian:function(){
      var is_login = common.checkLogin();
      if (!is_login) return;
      var that = this;
      var token = common.getToken();
      var userId = common.getUserId();
      var data = { token: token, userId: userId };
      var url = `${app.apiHost}centers/cashedloginfo`;     //发而评论接口
      var msg = ' ';
      var func = function (content) {
          if(!content.alipay||!content.realName){
              wx.navigateTo({
                  url: '/pages/tixian/tixian',
              })
          }else{
              wx.navigateTo({
                  url: '/pages/tixian/do_tixian',
              })
          }
      };
      var res = common.request(url, data, msg, func, that); 
  }
})
